/**
 * Created by LinJe on 2015/9/22.
 * 全局ui：登陆提示 弹窗
 */
(function( $, window ) {

    window.globalLayer = window.globalLayer || {};


    /**
     * 调用实例
     * window.globalLayer.openLogin({'callBack':function() {
            console.log('登陆提示窗已关闭');
       }});
     * @param settings
     */
    window.globalLayer.openLogin = function( settings ) {

        var loginArgs;

        //如果是第一次调用，加载弹窗所需html和js变量
        if ( !this.loginArgs ) {
            $("<link>").attr({ rel:"stylesheet", type:"text/css", href:"/static/huihuo/skin/default/layer_login.css"}).appendTo("head");
            $('body').append('\
                <div class="layer_login">\
                    <div class="popup-bg"></div>\
                    <div class="popup popup-login">\
                        <div class="content">\
                            <div class="title clearfix"><div class="btn"><span class="close" title="关闭"></span></div></div>\
                            <div class="text-con"><p>登录以继续操作</p></div>\
                            <div class="button"><span class="button-1">使用QQ一键登录</span><span class="button-2">取消</span></div>\
                        </div>\
                    </div>\
                </div>\
            ');

            loginArgs = this.loginArgs = {};
            loginArgs.$loginWrap = $('.layer_login');
            loginArgs.$colse = loginArgs.$loginWrap.find('.title .btn');
            loginArgs.$cancle = loginArgs.$loginWrap.find('.button .button-2');
            loginArgs.$loginQQ = loginArgs.$loginWrap.find('.button .button-1');

            //点击取消或者X 关闭弹窗
            loginArgs.$colse.on('click', function() { window.globalLayer.closeLogin(loginArgs.callBack) });
            loginArgs.$cancle.on('click', function() { window.globalLayer.closeLogin(loginArgs.callBack) });

            //点击 使用QQ一键登录
            loginArgs.$loginQQ.on('click', function() {

            });
        }

        loginArgs = this.loginArgs;
        $.extend(loginArgs, settings);

        loginArgs.$loginWrap.css({'opacity':'0', 'display':'block'}).stop().animate({ 'opacity': 1 });
    };


    window.globalLayer.closeLogin = function( callBack ) {

        this.loginArgs.$loginWrap.stop().animate({ 'opacity': 0 }, 500, '', function() {
            $(this).hide();
            callBack && callBack();
        });

    };

})( jQuery, window );